package com.awesome.spring.converter;

import com.awesome.spring.entity.Person;
import com.awesome.spring.model.PersonDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @program: awesome-spring
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-02-24 16:53
 **/

@Mapper(componentModel = "spring")
public interface PersonConverter {
    PersonConverter INSTANCE = Mappers.getMapper(PersonConverter.class);

    // 1.源对象属性与目标对象属性 名字一致，自动映射对应属性
//    @Mapping(source = "id",target = "id")

    // 2. 源对象属性与目标对象属性 名字不一致，需要指定 source-target
    @Mapping(source = "birthday",target = "birth")

    // 3.支持表达式的方式,例如可以用 format 转成自己想要的类型
//    @Mapping(source = "birthday",target = "birthDateFormat",dateFormat = "yyyy-HH-dd HH:mm:ss")
//    @Mapping(target = "birthExpressionFormat",dateFormat = "yyyy-HH-dd HH:mm:ss")

    // 4.如果某个属性你不想映射，可以加个 ignore=true
    @Mapping(source = "email",target = "email",ignore = true)
    PersonDTO toConvertPerson(Person person);

    List<PersonDTO> toConvertList(List<Person> person);
}
